package main

import (
	"fmt"
	"studentmsg"
)

func main() {
	msgList := &studentmsg.MsgList{}
	msgList.Init()
	fmt.Println("欢迎来到学生信息管理系统")
	fmt.Println("输入 1 查询所有学生信息")
	fmt.Println("输入 2 根据姓名或者学号查询学生信息")
	fmt.Println("输入 3 添加学生信息")
	fmt.Println("输入 4 删除学生信息")
	fmt.Println("输入 0 退出系统")
	var input string = ""
	var control int = 1
	for control == 1 {
		fmt.Println("请输入需要进行的操作编号")
		fmt.Scanf("%s", &input)
		fmt.Scanf("%s")
		switch input {
		case "0":
			control = 0
			break
		case "1":
			studentmsg.GetAllStudnets(msgList)
			break
		case "2":
			searchStudent(msgList)
			break
		case "3":
			addStudent(msgList)
			break
		case "4":
			deleteStudent(msgList)
			break
		default:
			fmt.Println("输入值无效，请重新输入")
			break
		}
	}
}

func searchStudent(l *studentmsg.MsgList) {
	var inputName string = ""
	var inputID string = ""
	fmt.Println("请输入学生姓名或者学号进行查找，姓名和学号允许为空")
	fmt.Println("姓名：")
	fmt.Scanf("%s", &inputName)
	fmt.Scanf("%s")
	fmt.Println("学号：")
	fmt.Scanf("%s", &inputID)
	fmt.Scanf("%s")
	studentmsg.SearchStudents(l, inputName, inputID)
}

func addStudent(l *studentmsg.MsgList) {
	var inputName string = ""
	var inputID string = ""
	var inputChineseGrades int = 0
	var inputMathGrades int = 0
	var inputEnglishGrades int = 0
	fmt.Println("请输入学生信息")
	fmt.Println("姓名：")
	fmt.Scanf("%s", &inputName)
	fmt.Scanf("%s")
	fmt.Println("学号：")
	fmt.Scanf("%s", &inputID)
	fmt.Scanf("%s")
	fmt.Println("语文成绩：")
	fmt.Scanf("%d", &inputChineseGrades)
	fmt.Scanf("%s")
	fmt.Println("数学成绩：")
	fmt.Scanf("%d", &inputMathGrades)
	fmt.Scanf("%s")
	fmt.Println("英语成绩：")
	fmt.Scanf("%d", &inputEnglishGrades)
	fmt.Scanf("%s")
	student := studentmsg.StudentMsg{}
	student.Init(
		inputName, inputID, inputChineseGrades, inputMathGrades, inputEnglishGrades,
	)
	result := studentmsg.AddStudent(l, &student)
	if result == true {
		fmt.Println("添加成功")
	} else {
		fmt.Println("添加失败")
	}
}

func deleteStudent(l *studentmsg.MsgList) {
	var inputIndex int = 0
	fmt.Println("请输入需要删除的学生的编号")
	fmt.Scanf("%d", &inputIndex)
	fmt.Scanf("%s")
	result := studentmsg.DeleteStudent(l, inputIndex)
	if result == true {
		fmt.Println("删除成功")
	} else {
		fmt.Println("删除失败")
	}
}
